from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

db = SQLAlchemy()

#TODO 自定义模型类



# 用户
class UserModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户ID')
    mobile = db.Column(db.String(11), comment='手机号')
    name = db.Column(db.String(32), comment='用户名')
    password = db.Column(db.String(32), comment='密码')
    img = db.Column(db.String(300), comment='头像')
    job = db.relationship('JobModel', backref='user')
    issue = db.relationship('IssueModel', backref='user')
    remark = db.relationship('RemarkModel', backref='user')
    prise = db.relationship('PriseModel', backref='user')


# 作业
class JobModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='作业ID')
    title = db.Column(db.Text, default='做完了！！！', comment='备注')
    status = db.Column(db.Boolean, default=False, comment='True：已批阅，False：未批阅')
    time = db.Column(db.DateTime, default=datetime.now, comment='时间')
    job_img = db.relationship('JobImgModel', backref='job')
    user_id = db.Column(db.Integer, db.ForeignKey('user_model.id'))


# 图片
class JobImgModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='作业图片ID')
    img = db.Column(db.String(300), comment='图片')
    job_id = db.Column(db.Integer, db.ForeignKey('job_model.id'))


# 问题
class IssueModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='问题ID')
    name = db.Column(db.String(100), comment='问题')
    title = db.Column(db.String(100), comment='原因')
    upload_time = db.Column(db.DateTime, default=datetime.now, comment='发布时间')
    user_id = db.Column(db.Integer, db.ForeignKey('user_model.id'))
    remark = db.relationship('RemarkModel', backref='issue')

# 评论
class RemarkModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='评论ID')
    title = db.Column(db.String(100), comment='解答')
    upload_time = db.Column(db.DateTime, default=datetime.now, comment='发布时间')
    issue_id = db.Column(db.Integer, db.ForeignKey('issue_model.id'))
    user_id = db.Column(db.Integer, db.ForeignKey('user_model.id'))
    prise = db.relationship('PriseModel', backref='remark')

# 点赞
class PriseModel(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='点赞ID')
    praise = db.Column(db.Boolean, default=False, comment='True：已点赞，False：未点赞')
    user_id = db.Column(db.Integer, db.ForeignKey('user_model.id'))
    remark_id = db.Column(db.Integer, db.ForeignKey('remark_model.id'))
